package cn.flexui.flexuiserver.controller.web;

import cn.dev33.satoken.stp.StpUtil;
import cn.flexui.flexuiserver.domain.constant.OauthConts;
import cn.flexui.flexuiserver.domain.entity.UserInfo;
import cn.flexui.flexuiserver.service.UserInfoService;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author wanmingyu
 * @create 2024/9/21 19:45
 */
@Tag(name = "测试")
@RequestMapping("/test")
@RestController
public class TestController {

    @Autowired
    private UserInfoService userInfoService;
    @PostMapping("/login")
    public String login(){
        Long id = 1L;
        UserInfo userInfo = userInfoService.getById(id);

        if(userInfo == null){
            userInfo = new UserInfo();
            userInfo.setOpenId("123");
            userInfo.setNickname("测试账户");
            userInfo.setUsername("测试账户");
            userInfo.setRemark("测试账户");
            userInfo.setAvatar("https://chat.apeto.cn/imgss/20240227/041ac29693b548d6bb30d66242caf7b7.png");
            userInfo.setPhone("13000202021");
            userInfo.setEmail("123@qq.com");
            userInfo.setPassword("123456");
            userInfo.setStatus(1);
            userInfo.setAuthType(OauthConts.AuthType.feishu.name());
            userInfoService.save(userInfo);
        }
        StpUtil.login(1);
        return StpUtil.getTokenValue();
    }
}
